What is @jsii/spec?
@jsii/spec is a package that provides TypeScript interfaces and JSON schema definitions for the jsii specification. It is used to define and validate the structure of jsii assemblies, which are used to enable interoperability between different programming languages.
What are @jsii/spec's main functionalities?
TypeScript Interfaces
This feature allows you to define and work with jsii assemblies using TypeScript interfaces. The code sample demonstrates how to create a basic jsii assembly object.
import { Assembly } from '@jsii/spec';
const assembly: Assembly = {
schema: 'jsii/0.10.0',
name: 'my-package',
version: '1.0.0',
description: 'A sample jsii package',
license: 'Apache-2.0',
dependencies: {},
bundled: [],
types: {},
targets: {}
};
console.log(assembly);
JSON Schema Definitions
This feature provides JSON schema definitions for jsii assemblies, allowing you to validate the structure of your jsii assembly objects. The code sample demonstrates how to use the Ajv library to validate a jsii assembly object against the schema.
const schema = require('@jsii/spec/schema.jsii.json');
const validate = (data) => {
const Ajv = require('ajv');
const ajv = new Ajv();
const validate = ajv.compile(schema);
const valid = validate(data);
if (!valid) console.log(validate.errors);
return valid;
};
const data = {
schema: 'jsii/0.10.0',
name: 'my-package',
version: '1.0.0',
description: 'A sample jsii package',
license: 'Apache-2.0',
dependencies: {},
bundled: [],
types: {},
targets: {}
};
console.log(validate(data));
Other packages similar to @jsii/spec
typescript-json-schema
typescript-json-schema is a package that generates JSON schema from your TypeScript types. It is similar to @jsii/spec in that it deals with JSON schema and TypeScript, but it focuses on generating schema from TypeScript code rather than defining and validating jsii assemblies.
ajv
Ajv is a JSON schema validator that can be used to validate JSON data against a schema. While @jsii/spec provides specific schema definitions for jsii assemblies, Ajv is a more general-purpose tool for JSON schema validation.
json-schema
json-schema is a package that provides a collection of JSON schema validation tools. It is similar to @jsii/spec in that it deals with JSON schema validation, but it is a more general-purpose library not specifically tailored to jsii assemblies.